Passing an Array to the API
This document outlines a use case demonstrating how to pass an array as an argument in API requests. This functionality allows users to dynamically provide an array of data in the request body, enhancing the flexibility and reusability of API tests.
The below example illustrates how to dynamically pass an array of URLs as an argument in the request body to create a new product using API in DevAssure.
-
Step 1: Define a variable
urlsas a code block containing an array of image URLs.
let urls = ["[https://placehold.co/600x400](https://placehold.co/600x400)", "[https://placehold.co/700x400](https://placehold.co/700x400)", "[https://placehold.co/800x400](https://placehold.co/800x400)"]; -
Step 2: Call the
FakeStoreAPI > CreateProductV2endpoint (POST) with theurlsvariable as thearrayUrlsargument. Store the API response inapiResponse_5.2. apiResponse_5 = Call API FakeStoreAPI > CreateProductV2 ( arrayUrls : urls )- Request Details:
- Method: POST
- URL:
https://api.escuelajs.co/api/v1/products/ - Body: JSON
{
"title": "gvdbnvd ejhdfvehvfe ejvfjerv",
"price": 10,
"description": "A description",
"categoryId": 1,
"images": "::arrayUrls"
} - Note: The
::arrayUrlsplaceholder in the JSON body is dynamically replaced with the array of URLs from theurlsvariable which is passed as an argument to the API definition
- Request Details: